import axios from 'axios'

import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

const baseURL = 'http://127.0.0.1:8888/api/private/v1/'

const service = axios.create({
  baseURL,
  timeout: 5000
})

service.interceptors.request.use(config => {
  NProgress.start()
  config.headers.Authorization = window.sessionStorage.getItem('token')
  return config
}, error => {
  console.log(error)
})
// 在 response 拦截器中，隐藏进度条
service.interceptors.response.use(config => {
  NProgress.done()
  return config
})

export default service
